package day05;

import java.util.Arrays;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/14
 */
public class ArrayExpansion {
    public static void main(String[] args) {
        int [] arr = new int [5];
        int size = -1;
        for (int i = 0; i < 6 ; i++) {
            size++;
            arr = addElement(arr, size, i*10);
            System.out.println(Arrays.toString(arr));
        }

    }

    public static int[] addElement(int[] array, int size, int element) {
        if (size == array.length) {
            int newCapacity = array.length * 3 / 2 + 1;
            int[] newArray = new int[newCapacity];
            System.arraycopy(array, 0, newArray, 0, array.length);
            array = newArray;
        }

        array[size] = element;
        return array;
    }

}
